$(function(){
    $('.mui-btn-primary').on('tap',function(){
        // console.log(111)
        if(window.loginflag){
            return false
        }
        var data = {
            username:$('[name="username"]').val(),
            password:$('[name="password"]').val()
        }
        // 判断用户名和密码是否为空
        if(!data.username){
            mui.toast('请输入用户名')
            return false
        }
        if(!data.password){
            mui.toast('请输入密码')
            return false
        }
        $.ajax({
            type:'post',
            url:'/user/login',
            data:data,
            dataType:'json',
            beforesend:function(){
                window.loginflag = true
            },
            success:function(data){
                // 登录成功后的两种操作，回跳，首页
                if(data.success){
                    // 1.回跳去product页面
                    if(location.search && location.search.indexOf('?returnUrl=') != -1){
                        var returnUrl = location.search.replace('?returnUrl=','')
                        location.href = returnUrl
                    }else{
                        // 2.跳转去首页
                        location.href = '/m/user/index.html'
                    }
                }else{
                    mui.toast('登录失败');
                }
                window.loginflag = false
            },
            error:function(){
                mui.toast('网络繁忙');
                window.loginflag = false
            }
        })
    })
})